<template>
  <div class="sidebarDiv">
    <transition name="menu-transition">
      <el-menu
        v-if="isOpen"
        class="el-menu-vertical-demo"
        background-color="#fff"
        text-color="grey"
        active-text-color="#001529"
      >
        <el-menu-item
          v-for="item in items"
          style="padding-left: 50px; font-size: 16px"
          :key="item.index"
          @click="beforeNavigate(item.index)"
        >{{ item.title }}</el-menu-item>
      </el-menu>
    </transition>
    <i @click="isOpen = !isOpen">
      <More v-if="!isOpen" class="icon" />
      <Close v-else class="icon" />
    </i>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { Close, More } from "@element-plus/icons-vue";

const isOpen = ref(false);
const items = ref([
  { index: "/Home", title: "首页" },
  { index: "/News", title: "新闻资讯" },
  { index: "/Case", title: "开设楼盘" },
  { index: "/GoIn", title: "走进民邦" },
]);

const beforeNavigate = (index) => {
  isOpen.value = false;
  const router = useRouter();
  router.push(index);
};
</script>

<style lang="scss" scoped>
.menu-transition-enter-active,
.menu-transition-leave-active {
  transition: all 0.3s linear;
}

.menu-transition-enter,
.menu-transition-leave-to {
  transform: translateX(-250px);
}

.el-menu-vertical-demo {
  will-change: transform, opacity;
  display: flex;
  padding-top: 100px;
  flex-direction: column;
  width: 45vw;
  min-height: 100vh;
}

.sidebarDiv {
  .icon {
    position: fixed;
    left: 10px;
    top: 20px;
    width: 28px;
  }
}
</style>